package com.voicechat.firstmet.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseAdapter;
import com.voicechat.firstmet.bean.CharmBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.adapter
 * @ClassName: MyTaskAdapter
 * @Description: java类作用描述
 * @Author: ljp
 * @CreateDate: 2018/11/18 14:00
 * @Version: 1.0
 */
public class MyTaskAdapter extends BaseAdapter<CharmBean.ObjectBean> {
    private int[] taskIcon ;
    private ItemClick itemClick;

    public void setItemClick(ItemClick itemClick) {
        this.itemClick = itemClick;
    }

    public void setTaskIcon(int[] taskIcon) {
        this.taskIcon = taskIcon;
    }

    /**
     * @param context activity_imessage
     * @param tlist   集合
     * @param mLayout 主布局
     */
    public MyTaskAdapter(Context context, List<CharmBean.ObjectBean> tlist, int mLayout) {
        super(context, tlist, mLayout);
    }

    @Override
    protected RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return null;
    }

    @Override
    protected RecyclerView.ViewHolder getItemViewHolder(View view) {
        return new ItemViewHolder(view);
    }

    @Override
    protected RecyclerView.ViewHolder getFooterViewHolder(View view) {
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        if(viewHolder instanceof ItemViewHolder){
            ItemViewHolder itemViewHolder = (ItemViewHolder) viewHolder;
            CharmBean.ObjectBean objectBean = tlist.get(position);
            itemViewHolder.taskGold.setText("金币+"+objectBean.getGold());
            itemViewHolder.taskName.setText(objectBean.getName());
            // 状态 (我的任务界面)   0 未领取  1 已经取 2未完成
            if(objectBean.getState() == 0){
                itemViewHolder.tvDataState.setText("领取奖励");
                itemViewHolder.tvDataState.setTextColor(context.getResources().getColor(R.color.colorWhite));
                itemViewHolder.tvDataState.setBackgroundResource(R.drawable.login_btn);
                itemViewHolder.tvDataState.setGravity(Gravity.CENTER);
            }else if(objectBean.getState() == 1){
                itemViewHolder.tvDataState.setText("已领取");
                itemViewHolder.tvDataState.setTextColor(context.getResources().getColor(R.color.color666666));
                itemViewHolder.tvDataState.setGravity(Gravity.RIGHT|Gravity.CENTER);
                itemViewHolder.tvDataState.setBackgroundResource(0);
            }else {
                itemViewHolder.tvDataState.setText("去完成");
                itemViewHolder.tvDataState.setTextColor(context.getResources().getColor(R.color.colorFF3B5E));
                itemViewHolder.tvDataState.setBackgroundResource(R.drawable.task_btn);
                itemViewHolder.tvDataState.setGravity(Gravity.CENTER);
            }

            itemViewHolder.taskIcon.setImageResource(taskIcon[position]);
            itemViewHolder.tvDataState.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClick.setItemState(objectBean);
                }
            });

        }
    }

    class ItemViewHolder extends BaseViewHolder{
        @BindView(R.id.task_icon)
        ImageView taskIcon;
        @BindView(R.id.task_name)
        TextView taskName;
        @BindView(R.id.task_gold)
        TextView taskGold;
        @BindView(R.id.tv_data_state)
        TextView tvDataState;
        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

    public interface ItemClick{
        void setItemState(CharmBean.ObjectBean objectBean);
    }
}
